﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 信息权限 数据类
    /// </summary>
    public class DocClsAuthority
    {
        public DocClsAuthority()
        {
        }
        /// <summary>
        /// 获取信息类别的权限数据
        /// <creator>wangl</creator>
        /// <date>2013-08-01</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docClsCd">信息类别编号</param>
        /// <returns>DataSet对象</returns>
        public DataSet GetListByClsCd(string entityNo, string docClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEntityNo,FDocClsCd,FSourceNo,FProp,FAuthorityType,FPronoun,allname ");
            strSql.Append(" FROM v_docClsAuthority ");
            strSql.Append(" WHERE FEntityNo=@FEntityNo AND FDocClsCd=@FDocClsCd");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25)
						};
            parameters[0].Value = entityNo;
            parameters[1].Value = docClsCd;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-08-01</date>
        /// </summary>
        /// <param name="row">DataRow对象</param>
        /// <returns>信息类别</returns>
        public Model.DocClsAuthority DataRowToModel(DataRow row)
        {
            Model.DocClsAuthority model = new Model.DocClsAuthority();
            if (row != null)
            {
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FDocClsCd"] != null)
                {
                    model.FDocClsCd = row["FDocClsCd"].ToString();
                }
                if (row["FSourceNo"] != null)
                {
                    model.FSourceNo = row["FSourceNo"].ToString();
                }
                if (row["FProp"] != null)
                {
                    model.FProp = row["FProp"].ToString();
                }
                if (row["FAuthorityType"] != null)
                {
                    model.FAuthorityType = row["FAuthorityType"].ToString();
                }
                if (row["FPronoun"] != null)
                {
                    model.FPronoun = row["FPronoun"].ToString();
                }
                if (row.Table.Columns.Contains("allname"))
                {
                    if (row["allname"] != null)
                    {
                        model.AllName = row["allname"].ToString();
                    }
                }
            }
            return model;
        }
        /// <summary>
        /// 获得某个用户在某类别上有发布权限的所有部门
        /// <creator>wangl</creator>
        /// <date>2013-08-01</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="emplNo">员工编号</param>
        /// <param name="docClsCd">信息编号</param>
        /// <returns>DataSet对象</returns>
        public DataSet GetDeptInDodAuthority(string entityNo, string emplNo, string docClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from fn_getDocClsPubDept(");
            strSql.Append(" @FEntityNo,@FDocClsCd,@FEmplNo)");

            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25),					
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = docClsCd;
            parameters[2].Value = emplNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }
        /// <summary>
        /// 获得某个用户在某类别上有发布权限的所有工作组
        /// <creator>wangl</creator>
        /// <date>2013-08-01</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="emplNo">员工编号</param>
        /// <param name="docClsCd">信息编号</param>
        /// <returns>DataSet对象</returns>
        public DataSet GetGroupInDodAuthority(string entityNo, string emplNo, string docClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from fn_getDocClsPubWorkGrp(");
            strSql.Append(" @FEntityNo,@FDocClsCd,@FEmplNo)");

            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25),
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = docClsCd;
            parameters[2].Value = emplNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }

    }
}
